(use-package :leam)
(clc:clc-require :flexi-streams)

(defun test-leam-data-stream()
  (let ((data (flexi-streams:with-output-to-sequence (stream)
		(let ((test-out
		       (make-instance 'leam-data-out-stream
				      :stream-length 6
				      :data-stream stream)))
		  (write-unsigned-8 test-out 30)
		  (write-unsigned-8 test-out 255)
		  (write-unsigned-8 test-out 100)
		  (assert (= 3 (get-remaining test-out)))
		  (write-byte-data test-out
				   (make-array 3
					       :element-type '(unsigned-byte 8)
					       :initial-element 30))
		  (assert (= 0 (get-remaining test-out)))))))
    (assert (= 6 (length data)))
    (flexi-streams:with-input-from-sequence (stream data)
      (let ((test-in (make-instance 'leam-data-in-stream
				    :stream-length 6
				    :data-stream stream))
	    (data-vec (make-array 3 :initial-element 0
				  :element-type '(unsigned-byte 8)
				  :fill-pointer 3 )))
	(assert (= 30 (read-unsigned-8 test-in)))
	(assert (= 255 (read-unsigned-8 test-in)))
	(assert (= 100 (read-unsigned-8 test-in)))
	(assert (= 3 (get-remaining test-in)))
	(read-byte-data test-in data-vec)
	(assert (= 30 (aref data-vec 0)))
	(assert (= 30 (aref data-vec 1)))
	(assert (= 30 (aref data-vec 2)))
	(assert (= 0 (get-remaining test-in)))))))

(defun leam-data-stream-test-all()
  (test-leam-data-stream))


				 
